package com.alarm.ecp;

import com.alarm.ecp.pojo.EventPO;
import org.apache.flink.cep.pattern.conditions.IterativeCondition;

import java.util.Objects;

public class IpChangeCondition extends IterativeCondition<EventPO> {
    @Override
    public boolean filter(EventPO eventPO, Context<EventPO> context) throws Exception {
        boolean change = false;
        // 当前模式名称是“IP”,获取当前模式之前已匹配的事件
        for(EventPO preEvent:  context.getEventsForPattern("ip")){
            // 前一个行为事件的IP
            String preIp = preEvent.getIp();
            // 当前行为事件的IP
            String ip = eventPO.getIp();

            //  判断IP是否改变
            if(!Objects.equals(preIp, ip)){
                change = true;
                break;
            }
        }
        return change;
    }
}
